package com.jxb.demo.im;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import org.msgpack.MessagePack;
import java.util.List;

/**
 * @desc 解码器
 */
public class MsgPackDecoder extends MessageToMessageDecoder<ByteBuf> {

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        byte[]bytes = new byte[byteBuf.readableBytes()];
        byteBuf.readBytes(bytes);
        MessagePack msgPack = new MessagePack();
        list.add(msgPack.read(bytes,MsgInfo.class));
    }

}
